﻿package 
{

	public class KnowlegdeBase
	{
		public var records:Array = new Array();
		private var taggedCount:int;

		public function KnowlegdeBase()
		{
			taggedCount = 0;
		}

		private function hornOnElements(item:ElemRecord)
		{
			for each (var it:int in item.conectedArr)
			{
				horn(records[it]);
			}
		}

		public function horn(record:Array=null):Boolean
		{

			if (record==null)
			{
				for each (var it:* in records)
				{
					if (it[0].tag) taggedCount--; hornOnElements(it[0]);

				}

			}
			else
			{
				record[0].checkedCount++;
				if (record[0].checkedCount == record[0].recordLen)
				{
					taggedCount--;
					record[0].tag = true;
					hornOnElements(record[0]);
				}


			}

			return (taggedCount==0)? true : false;
		}

		public function addRecord(inp:Array)
		{

			records.push(inp);
			inp[0].recordLen = inp.length - 1;
			for (var i:int=1; i<inp.length; i++)
			{

				inp[i].conectedArr.push(records.length-1);

			}
			taggedCount++;

		}

	}

}